

Function Generate_CaseResult_XML_Segment(str_XMLPath,dic_CaseInfo)
   Set xmlDoc = CreateObject("Microsoft.XMLDOM")
	xmlDoc.async = False
	xmlDoc.load(str_XMLPath)

	'===create node names===
	Set new_TestCase_Element = xmlDoc.createElement("TestCase")
		Set new_CaseName_Element = xmlDoc.createElement("CaseName")
		Set new_Number_Element = xmlDoc.createElement("Number")
		Set new_Asset_Element = xmlDoc.createElement("Asset")
		Set new_ErrorLog_Element = xmlDoc.createElement("ErrorLog")
		Set new_SAPMessage_Element = xmlDoc.createElement("SAPMessage")
		Set new_CaseStatus_Element = xmlDoc.createElement("CaseStatus")
		Set new_ErrorSnapshot_Element = xmlDoc.createElement("ErrorSnapshot")
		Set new_InputDatas_Element = xmlDoc.createElement("InputDatas")			
		Set new_OutputDatas_Element = xmlDoc.createElement("OutputDatas")			
		Set new_CheckPoints_Element = xmlDoc.createElement("CheckPoints")
		set new_ItemList_Element = xmlDoc.createElement("ItemList")

	'===Head information===
		'value
		Set new_CaseName_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("Case Name"))
		Set new_Number_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("No"))
		Set new_Asset_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("Asset"))
		Set new_ErrorLog_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("Error Log"))
		Set new_SAPMessage_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("SAP message"))
		Set new_CaseStatus_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("Case Status"))
		Set new_ErrorSnapshot_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("ErrorCapture"))

		new_CaseName_Element.appendChild(new_CaseName_TextNode)
		new_Number_Element.appendChild(new_Number_TextNode)
		new_Asset_Element.appendChild(new_Asset_TextNode)
		new_ErrorLog_Element.appendChild(new_ErrorLog_TextNode)
		new_SAPMessage_Element.appendChild(new_SAPMessage_TextNode)
		new_CaseStatus_Element.appendChild(new_CaseStatus_TextNode)
		new_ErrorSnapshot_Element.appendChild(new_ErrorSnapshot_TextNode)

	new_TestCase_Element.appendChild(new_CaseName_Element)
	new_TestCase_Element.appendChild(new_Number_Element)
	new_TestCase_Element.appendChild(new_Asset_Element)
	new_TestCase_Element.appendChild(new_ErrorLog_Element)
	new_TestCase_Element.appendChild(new_SAPMessage_Element)
	new_TestCase_Element.appendChild(new_CaseStatus_Element)
	new_TestCase_Element.appendChild(new_ErrorSnapshot_Element)

    
	'===inputs===
	'print dic_CaseInfo.item("InputData").count
	If dic_CaseInfo.item("InputData").count <> 0 then
		For i = 0 to dic_CaseInfo.item("InputData").count -1
				Set new_InputData_Element = xmlDoc.createElement("InputData")
					Set new_FieldName_Element = xmlDoc.createElement("FieldName")
					Set new_FieldValue_Element = xmlDoc.createElement("FieldValue")
					'value
					Set new_FieldName_TextNode =  xmlDoc.createTextNode( dic_CaseInfo.item("InputData").key(i))
					Set new_FieldValue_TextNode =  xmlDoc.createTextNode(dic_CaseInfo.item("InputData").item(i))

					new_FieldName_Element.appendChild(new_FieldName_TextNode)
					new_FieldValue_Element.appendChild(new_FieldValue_TextNode)
				new_InputData_Element.appendChild(new_FieldName_Element)
				new_InputData_Element.appendChild(new_FieldValue_Element)
			new_InputDatas_Element.appendChild(new_InputData_Element)
		Next
	end if
	new_TestCase_Element.appendChild(new_InputDatas_Element)
    
	
	'===outputs===
	'print dic_CaseInfo.item("OutputData").count
	If  dic_CaseInfo.item("OutputData").count <> 0 then
	For i = 0 to dic_CaseInfo.item("OutputData").count-1
			Set new_OutputData_Element = xmlDoc.createElement("OutputData")			
				Set new_FieldName_Element = xmlDoc.createElement("FieldName")
				Set new_FieldValue_Element = xmlDoc.createElement("FieldValue")
				'Value 
				Set new_FieldName_TextNode =  xmlDoc.createTextNode(dic_CaseInfo.item("OutputData").key(i))
				Set new_FieldValue_TextNode =  xmlDoc.createTextNode(dic_CaseInfo.item("OutputData").item(i))

				new_FieldName_Element.appendChild(new_FieldName_TextNode)
				new_FieldValue_Element.appendChild(new_FieldValue_TextNode)
			new_OutputData_Element.appendChild(new_FieldName_Element)
			new_OutputData_Element.appendChild(new_FieldValue_Element)
		new_OutputDatas_Element.appendChild(new_OutputData_Element)
	Next
	End if
	new_TestCase_Element.appendChild(new_OutputDatas_Element)

	'==ItemList======
	If dic_CaseInfo.item("ItemList").count <> 0 then
		'ColumnName
		Set new_ColumnNames_Element = xmlDoc.createElement("ColumnNames")
		For iColumnCount = 0 to dic_CaseInfo.item("ItemList").count - 1			
			Set new_ColumnName_Element = xmlDoc.createElement("ColumnName")	
			set new_ColumnName_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("ItemList").key(iColumnCount))
			new_ColumnName_Element.appendChild(new_ColumnName_TextNode)
			new_ColumnNames_Element.appendChild(new_ColumnName_Element)
		Next
		new_ItemList_Element.appendChild(new_ColumnNames_Element)
		
		'ColumnValue
		for iRowCount = 1 to dic_CaseInfo.item("ItemList").item(0).count'count of rows
			Set new_ColumnValues_Element = xmlDoc.createElement("ColumnValues")
			for iiColumnCount = 0 to dic_CaseInfo.item("ItemList").count - 1 'count of columes
				Set new_ColumnValue_Element =  xmlDoc.createElement("ColumnValue")
				Set new_ColumnValue_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("ItemList").item(iiColumnCount).item(iRowCount))
				new_ColumnValue_Element.appendChild(new_ColumnValue_TextNode)
				new_ColumnValues_Element.appendChild(new_ColumnValue_Element)
			Next
			new_ItemList_Element.appendChild(new_ColumnValues_Element)
		Next
		
		new_TestCase_Element.appendChild(new_ItemList_Element)	
	End if	
	
	
	'===checkpoints===
	'print dic_CaseInfo.item("CaseResult").count
	If dic_CaseInfo.item("CaseResult").count <> 0 then
		For i = 0 to dic_CaseInfo.item("CaseResult").count-1
				Set new_CheckPoint_Element = xmlDoc.createElement("CheckPoint")
					Set new_CPSN_Element = xmlDoc.createElement("CPSN")
					Set new_CPName_Element = xmlDoc.createElement("CPName")
					Set new_CPTime_Element = xmlDoc.createElement("CPTime")
					Set new_CPExpected_Element = xmlDoc.createElement("CPExpected")
					Set new_CPActual_Element = xmlDoc.createElement("CPActual")
					Set new_CPStatus_Element = xmlDoc.createElement("CPStatus")
					Set new_CPSnapshot_Element = xmlDoc.createElement("CPSnapshot")
					'value
					Set new_CPSN_TextNode = xmlDoc.createTextNode(i)
					Set new_CPName_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("CaseResult").item(i).item("CheckPoint Name"))
					Set new_CPTime_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("CaseResult").item(i).item("Executed Time"))
					Set new_CPExpected_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("CaseResult").item(i).item("Expected Result"))
					Set new_CPActual_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("CaseResult").item(i).item("Actual Result"))
					Set new_CPStatus_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("CaseResult").item(i).item("Status"))
					Set new_CPSnapshot_TextNode = xmlDoc.createTextNode(dic_CaseInfo.item("CaseResult").item(i).item("Snapshot"))

					new_CPSN_Element.appendChild(new_CPSN_TextNode)
					new_CPName_Element.appendChild(new_CPName_TextNode)
					new_CPTime_Element.appendChild(new_CPTime_TextNode)
					new_CPExpected_Element.appendChild(new_CPExpected_TextNode)
					new_CPActual_Element.appendChild(new_CPActual_TextNode)
					new_CPStatus_Element.appendChild(new_CPStatus_TextNode)
					new_CPSnapshot_Element.appendChild(new_CPSnapshot_TextNode)
		
				new_CheckPoint_Element.appendChild(new_CPSN_Element)
				new_CheckPoint_Element.appendChild(new_CPName_Element)
				new_CheckPoint_Element.appendChild(new_CPTime_Element)
				new_CheckPoint_Element.appendChild(new_CPExpected_Element)
				new_CheckPoint_Element.appendChild(new_CPActual_Element)
				new_CheckPoint_Element.appendChild(new_CPStatus_Element)
				new_CheckPoint_Element.appendChild(new_CPSnapshot_Element)

			new_CheckPoints_Element.appendChild(new_CheckPoint_Element)
		Next
	End if
	new_TestCase_Element.appendChild(new_CheckPoints_Element)

	'root append
	xmlDoc.getElementsByTagName("Detail")(0).appendChild(new_TestCase_Element)

	'save and close	 
	xmlDoc.save(str_XMLPath)
	Set xmlDoc = Nothing
End Function

Function Update_XML_HeadData(str_XMLPath,dic_PlanInfor)
	Set xmlDoc = CreateObject("Microsoft.XMLDOM")
	xmlDoc.async = False
	xmlDoc.load(str_XMLPath)
	'iSummaryItems = xmlDoc.getElementsByTagName("Summary")(0).childNodes.length

	'get text node
	set CurrentSAPguiVersion_TextNode = xmlDoc.getElementsByTagName("SAPVersion")(0).childNodes(0)
	set TestEnvironment_TextNode = xmlDoc.getElementsByTagName("TestEnvironment")(0).childNodes(0)
	set CompanyCode_TextNode = xmlDoc.getElementsByTagName("CompanyCode")(0).childNodes(0)
	set RunMode_TextNode = xmlDoc.getElementsByTagName("RunMode")(0).childNodes(0)
	set TestName_TextNode = xmlDoc.getElementsByTagName("TestName")(0).childNodes(0)
	set ExecutedOn_TextNode = xmlDoc.getElementsByTagName("ExecutedOn")(0).childNodes(0)
	set TotalScripts_TextNode = xmlDoc.getElementsByTagName("TotalScripts")(0).childNodes(0)
	set TimeZone_TextNode = xmlDoc.getElementsByTagName("TimeZone")(0).childNodes(0)
	set TestStartTime_TextNode = xmlDoc.getElementsByTagName("TestStartTime")(0).childNodes(0)	
	set TestEndTime_TextNode = xmlDoc.getElementsByTagName("TestEndTime")(0).childNodes(0)
	set QCTestSet_TextNode = xmlDoc.getElementsByTagName("ALMTestSet")(0).childNodes(0)
	set QCInstance_TextNode = xmlDoc.getElementsByTagName("ALMInstance")(0).childNodes(0)	
	set ContinueExecution_TextNode = xmlDoc.getElementsByTagName("ContinueExecution")(0).childNodes(0)

	'set value for text node
	CurrentSAPguiVersion_TextNode.nodeValue = dic_PlanInfor.item("CurrentSAPguiVersion")
    TestEnvironment_TextNode.nodeValue = dic_PlanInfor.item("TestEnvironment")
	CompanyCode_TextNode.nodeValue = dic_PlanInfor.item("Company Code")
	RunMode_TextNode.nodeValue = dic_PlanInfor.item("RunMode")
	TestName_TextNode.nodeValue = dic_PlanInfor.item("QCTestName")
	ExecutedOn_TextNode.nodeValue = dic_PlanInfor.item("ExecutedOn")
	TotalScripts_TextNode.nodeValue = dic_PlanInfor.item("TotalScripts")
	TimeZone_TextNode.nodeValue = dic_PlanInfor.item("TimeZone")
	TestStartTime_TextNode.nodeValue = dic_PlanInfor.item("StartTime")
	TestEndTime_TextNode.nodeValue = dic_PlanInfor.item("EndTime")
	QCTestSet_TextNode.nodeValue = dic_PlanInfor.item("QCTestSet")
	QCInstance_TextNode.nodeValue = dic_PlanInfor.item("QCInstance")	
	ContinueExecution_TextNode.nodeValue = dic_PlanInfor.item("ContinueExecution")

	xmlDoc.save(str_XMLPath)
	Set xmlDoc = nothing
End Function

Function Load_XML_HeadData(str_XMLPath)
	Set xmlDoc = CreateObject("Microsoft.XMLDOM")
	xmlDoc.async = False
	xmlDoc.load(str_XMLPath)

	'modify
	Set dic_ResultHead = [new NewDictionary]
	set CurrentSAPguiVersion_TextNode = xmlDoc.getElementsByTagName("SAPVersion")(0).childNodes(0)
	set TestEnvironment_TextNode = xmlDoc.getElementsByTagName("TestEnvironment")(0).childNodes(0)
	set CompanyCode_TextNode = xmlDoc.getElementsByTagName("CompanyCode")(0).childNodes(0)
	set RunMode_TextNode = xmlDoc.getElementsByTagName("RunMode")(0).childNodes(0)
	set TestName_TextNode = xmlDoc.getElementsByTagName("TestName")(0).childNodes(0)
	set ExecutedOn_TextNode = xmlDoc.getElementsByTagName("ExecutedOn")(0).childNodes(0)
	set TotalScripts_TextNode = xmlDoc.getElementsByTagName("TotalScripts")(0).childNodes(0)
	set TimeZone_TextNode = xmlDoc.getElementsByTagName("TimeZone")(0).childNodes(0)
	set TestStartTime_TextNode = xmlDoc.getElementsByTagName("TestStartTime")(0).childNodes(0)	
	set TestEndTime_TextNode = xmlDoc.getElementsByTagName("TestEndTime")(0).childNodes(0)
	set ContinueExecution_TextNode = xmlDoc.getElementsByTagName("ContinueExecution")(0).childNodes(0)	
	set QCTestSet_TextNode = xmlDoc.getElementsByTagName("ALMTestSet")(0).childNodes(0)
	set QCInstance_TextNode = xmlDoc.getElementsByTagName("ALMInstance")(0).childNodes(0)
	
	
	dic_ResultHead.add "CurrentSAPguiVersion",CurrentSAPguiVersion_TextNode.nodeValue
	dic_ResultHead.add "TestEnvironment",TestEnvironment_TextNode.nodeValue
	dic_ResultHead.add "Company Code",CompanyCode_TextNode.nodeValue
	dic_ResultHead.add "RunMode",RunMode_TextNode.nodeValue
	dic_ResultHead.add "QCTestName",TestName_TextNode.nodeValue
	dic_ResultHead.add "ExecutedOn",ExecutedOn_TextNode.nodeValue
	dic_ResultHead.add "TotalScripts",TotalScripts_TextNode.nodeValue
	dic_ResultHead.add "TimeZone",TimeZone_TextNode.nodeValue
	dic_ResultHead.add "StartTime",TestStartTime_TextNode.nodeValue
	dic_ResultHead.add "EndTime",TestEndTime_TextNode.nodeValue
	dic_ResultHead.add "ContinueExecution",ContinueExecution_TextNode.nodeValue
	dic_ResultHead.add "QCTestSet",QCTestSet_TextNode.nodeValue
	dic_ResultHead.add "QCInstance",QCInstance_TextNode.nodeValue
	

	xmlDoc.save(str_XMLPath)
	Set xmlDoc = nothing
	Set Load_XML_HeadData = dic_ResultHead	
End Function
